/**
 * 
 */
package com.shine.icis.dao.imp;

import org.hibernate.Query;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.sql.hibernate.CommQuery;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.icis.dao.IAllotmentConfDAO;
import com.shine.icis.dao.imp.BaseHibernateDAO;
import com.shine.icis.hbean.AllotmentConf;

/**
 * 上海配股配置
 * @author zhangxr
 *
 */
public class AllotmentConfDAO extends BaseHibernateDAO implements IAllotmentConfDAO {
	
	@SuppressWarnings("unchecked")
	@Override
	public ListPage<AllotmentConf> findAllotmentConfPage(QueryParameters qp) {
		if (qp == null) {
			throw new IllegalArgumentException("非法参数:查询参数对象为null");
		}
		try {
			StringBuffer sbQueryString = new StringBuffer();			
			sbQueryString.append("select af from AllotmentConf as af where 1=1");
			
			return new CommQuery<AllotmentConf>().queryListPage(qp, 
					qp.appendOrders(sbQueryString, "af" ), getSession());
		} catch(RuntimeException re) {
			re.printStackTrace();
			return new  ListPage<AllotmentConf>();
		}
	}
	/**
	 * 新增配股配置信息
	 * @author zhangxr
	 * */
	public void saveAllotmentConf(AllotmentConf conf) {
		this.save(conf);
	}
	
	/**
	 * 更新配股配置信息
	 * @author zhangxr
	 * */
	public void updateAllotmentConf(AllotmentConf conf) {
		Query query = this.getSession().createQuery(" update AllotmentConf set secCode=:secCode,allCode=:allCode,startDate=:startDate,endDate = :endDate,operDate=:operDate,operTime=:operTime where confId=:confId");
		query.setString("secCode", conf.getSecCode());
		query.setString("allCode", conf.getAllCode());
		query.setInteger("startDate", conf.getStartDate());
		query.setInteger("endDate", conf.getEndDate());
		query.setInteger("operDate", conf.getOperDate());
		query.setInteger("operTime", conf.getOperTime());
		query.setInteger("confId", conf.getConfId());
		query.executeUpdate();
	}
	/**
	 * 删除配股配置信息
	 * @author zhangxr
	 * */
	public void deleteAllotmentConf(Integer confId) {
		Query query = this.getSession().createQuery(" delete AllotmentConf where confId=:confId");
		query.setInteger("confId", confId);
		query.executeUpdate();
	}	
}
